package org.monster.context.reader;

import org.dom4j.Element;
import org.monster.context.reader.tag.MimeTag;

import java.util.List;

/**
 * 多媒体互联网格式阅读器
 *
 * @param <E>
 * @author Monster
 */
public class MimeReader<E> extends XmlReader {

    private static final String EXTENSION = "extension";
    private static final String MIME_MAPPING = "mime-mapping";

    /**
     * 解析元素
     * 解析MIme的Element并添加父类的xml标签
     *
     * @param element 元素
     */
    @Override
    public void resolveElement(Element element) {
        List<Element> mimeMappings = element.elements(MIME_MAPPING);
        for (Element mimeMapping : mimeMappings) {
            List<Element> elements = mimeMapping.elements();
            MimeTag mime = new MimeTag();
            for (Element ele : elements) {
                if (nameEquals(ele, EXTENSION)) {
                    mime.setExtension(ele.getText());
                } else {
                    mime.setMimeType(ele.getText());
                }
            }
            getXmlTags().add(mime);
        }
    }

    /**
     * 获取 标签
     *
     * @param name 名称
     * @return 标签
     */
    @Override
    public MimeTag getTag(String name) {
        return null;
    }

    /**
     * 获取 标签 集合
     *
     * @return 标签 集合
     */
    @Override
    public List<E> getTags() {
        return getXmlTags();
    }
}
